package com.data.center.controller.mongo;
import com.data.center.entity.mongo.MongoExpert;
import com.data.center.service.mongo.MongoExpertService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;
@RestController
@RequestMapping("/api/experts")
public class MongoExpertController {
    @Autowired
    private MongoExpertService expertService;

    @GetMapping
    public List<MongoExpert> getAllExperts() {
        return expertService.getAllExperts();
    }

    @GetMapping("/{expertId}")
    public ResponseEntity<MongoExpert> getExpertById(@PathVariable String expertId) {
        Optional<MongoExpert> expert = expertService.getExpertById(expertId);
        return expert.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
    }

    @PostMapping
    public MongoExpert createExpert(@RequestBody MongoExpert expert) {
        return expertService.saveExpert(expert);
    }

    @DeleteMapping("/{expertId}")
    public ResponseEntity<Void> deleteExpert(@PathVariable String expertId) {
        expertService.deleteExpert(expertId);
        return ResponseEntity.noContent().build();
    }

}
